package cn.edu.gzist.rabbit.service;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageProducerService {

    private AmqpAdmin admin;
    @Autowired
    public MessageProducerService(AmqpAdmin amqpAdmin){
        this.admin = amqpAdmin;
        // 1. 定义exchange，名为 direct.exchange
        this.admin.declareExchange(new DirectExchange("direct.exchange"));
        // 2. 定义queue，名为 email.queue
        this.admin.declareQueue(new Queue("email.queue"));
        // 3. 定义Binding，将exchange与queue进行绑定
        this.admin.declareBinding(new Binding("email.queue",Binding.DestinationType.QUEUE,"direct.exchange","",null));
    }
}
